<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="__STATIC__/template/favicon.ico" >
    <link rel="Shortcut Icon" href="__STATIC__/template/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="__STATIC__/template/lib/html5shiv.js"></script>
    <script type="text/javascript" src="__STATIC__/template/lib/respond.min.js"></script>

    <![endif]-->
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/lib/Hui-iconfont/1.0.8/iconfont.css" />

    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="__STATIC__/template/static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="__STATIC__/template/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!--/meta 作为公共模版分离出去-->
    <!--css 加载 -->
    {load file='_CSS_/diyUpload.css'}
    {load file='_CSS_/webuploader.css'}

</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span>商城管理
    <span class="c-gray en">&gt;</span> <span style="color: red">商品添加</span>
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>
<div class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-product-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>标题：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$res?$res.title:''}"  placeholder="必填" id="title" name="title">
            </div>
            <span id="title_tip"></span>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>分类：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width: 25%" >
				<select name="" class="select contact" id="rt_id">
                    {foreach name='type' item='v'}
                    <option value="{$v.id}" {$res ? ($res.type == $v.id ? "selected = 'selected'":''):''}>{$v.name}</option>
                    {/foreach}
                </select>
				</span>

            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2" >图片：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="weui-uploader__bd test" id="test" style="display:inline-block"></div>
                <span id="filename" style="vertical-align: middle">最多上传5张(<span style="color: blue">建议将文件处理成小于2M的图片</span>)</span>
            </div>
        </div>
        {notempty name='$res.images'}
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">缩略图：</label>
            <div class="formControls col-xs-8 col-sm-9" style="min-height: 100px;margin-left: 5px">
                {foreach name="$res.images" item="v"}
                <div style="width:100px;height:100px;display: inline-block;text-align: center" class="col-xs-8 col-sm-9">
                    <img src="__UPLOADS__/{$v}" style="width:80px;height:80px;border-radius: 5px;border: 1px solid lightgrey"/>
                    <a onclick="imgDel(this)" class="img1" data-img="{$v}" style="" href="javascript:;">
                        删除
                    </a>
                </div>
                {/foreach}
            </div>
        </div>
        {/notempty}

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">商品摘要：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea name="intro"  id='intro' cols="" rows="" class="textarea"  placeholder="">{$res?$res.intro:''}</textarea>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">详细内容：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea id="editor" type="text/plain" style="width:100%;height:400px;">{$res?$res.content:''}</textarea>
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                {empty name='$res'}
                    <button onClick="product_save_submit();" class="btn btn-primary radius" type="button">
                        <i class="Hui-iconfont">&#xe632;</i> 提交
                    </button>
                {else /}
                    <input type="hidden" value="{$res.id}" id="reveal_id"/>
                    <button onClick="product_edit_submit();" class="btn btn-primary radius" type="button">
                        <i class="Hui-iconfont">&#xe632;</i> 修改
                    </button>
                {/empty}
                <button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="__STATIC__/template/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="__STATIC__/template/lib/layer/2.4/layer.js"></script>
<!--
<script type="text/javascript" src="__STATIC__/template/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="__STATIC__/template/static/h-ui.admin/js/H-ui.admin.js"></script>
-->
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/template/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/template/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/template/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__STATIC__/template/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<!-- 加载js -->
{load file='_LIB_/jquery-2.1.4.js'}
{load file='_LIB_/fastclick.js'}
{load file='_JS_/jquery.Spinner.js'}
{load file='_JS_/jquery-weui.js'}
{load file='_LIB_/diyUpload.js'}
{load file='_LIB_/webuploader.min.js'}
<script type="text/javascript">

    /*富文本编辑器*/
    var images="";
    $(function(){
        var ue = UE.getEditor('editor');
        // 图片上传
        var l = $('.img1').length;
        if(l<5){
            var num = 5-l;
            $('#filename').html('还可以上传'+num+'张('+'<span style="color: blue">建议将文件处理成小于2M的图片</span>'+')');
            $("#test").diyUpload({
                url:"{:url('admin/Uploads/index')}",
                fileNumLimit:5,
                fileSizeLimit:1024 * 1024*30,
                fileSingleSizeLimit:1024 * 1024*30,
                success:function( data ) {
                    console.log( data );
                    if(data.ok){
                        images+=data.img+",";
                        $('#filename').text('文件上传成功！').css('color','green');
                    }else{
                        $('#filename').text(err.msg).css('color','red');
                    }

                },
                error:function( err ) {
                    console.info( err );
                    if(err.ok==false){
                        $('#filename').text(err.msg).css('color','red');
                    }

                }
            });

        }

    });

    /*图片删除*/
    function imgDel(obj){
        $(obj).parent().remove();
        var l = $('.img1').length;
        var num = 5-l;
        $('#filename').html('还可以上传'+num+'张('+'<span style="color: blue">建议将文件处理成小于2M的图片</span>'+')');
    }
    /* 添加 */
    function product_save_submit(){
        var title   = $.trim($('#title').val());
        var intro   = $.trim($('#intro').val());
        var type   = $('#rt_id').val();
        var content 	= UE.getEditor('editor').getContent() ;//富文本内容 商品详情内容

        var data = {
            title:title,
            intro:intro,
            type:type,
            images:images,
            content:content
        };

        var url = "{:url('admin/Reveal/reveal_hold')}";
        $.post(url,data,function(res){
            console.log(res);
            if(res.ok){
                layer.msg(res.msg,{icon: 1,time:2000});
                setTimeout("window.location.replace(location.href)",2000);
            }else{
                layer.msg(res.msg,{icon: 5,time:2000});
            }
        })
    }

    /* 修改 */
    function product_edit_submit(){
        var reveal_id = $('#reveal_id').val();
        var title     = $.trim($('#title').val());
        var intro     = $.trim($('#intro').val());
        var type      = $('#rt_id').val();
        var content   = UE.getEditor('editor').getContent() ;//富文本内容 商品详情内容
        var img1      = '';

        $('.img1').each(function(e){
            img1 += $(this).attr('data-img')+',';
        })

        var img = img1+images;
//alert(img1);
        var data = {
            reveal_id:reveal_id,
            title:title,
            intro:intro,
            type:type,
            images:img,
            content:content
        };

        var url = "{:url('admin/Reveal/reveal_edit')}";
        $.post(url,data,function(res){
            console.log(res);
            if(res.ok){
                layer.msg(res.msg,{icon: 1,time:2000});
                setTimeout(window.location.href="{:url('index')}",2000);
            }else{
                layer.msg(res.msg,{icon: 5,time:2000});
            }
        })
    }



</script>
</body>
</html>